package com.ruoyi.web.controller.base;

import com.ruoyi.base.domain.BaseMeeting;
import com.ruoyi.base.service.IBaseMeetingService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.UUID;


@RestController
@RequestMapping("/base/baseMeeting")
public class BaseMeetingController extends BaseController {

    @Autowired
    private IBaseMeetingService baseMeetingService;

    @ApiOperation("查询会议列表")
    @GetMapping("/list")
    public TableDataInfo list(BaseMeeting baseMeeting) {
        startPage();
        if (baseMeeting==null )
            baseMeeting = new BaseMeeting();
        List<BaseMeeting> list = baseMeetingService.selectBaseMeetingList(baseMeeting);
        return getDataTable(list);
    }


    @ApiOperation("新增会议")
    @Log(title = "新增会议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseMeeting baseMeeting) {
        baseMeeting.setID(UUID.randomUUID().toString().replace("-", ""));
        baseMeeting.setCreatedBy(getUserId().toString());
        baseMeeting.setCreatedTime(new Date());
        return toAjax(baseMeetingService.insertBaseMeeting(baseMeeting));
    }


    @ApiOperation("修改会议")
    @Log(title = "修改会议", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseMeeting baseMeeting) {
        baseMeeting.setUpdatedBy(getUserId().toString());
        baseMeeting.setUpdatedTime(new Date());
        return toAjax(baseMeetingService.updateBaseMeeting(baseMeeting));
    }


    @ApiOperation("删除会议")
    @Log(title = "删除会议", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ID}")
    public AjaxResult remove(@PathVariable String ID) {
        return toAjax(baseMeetingService.deleteBaseMeetingById(ID));
    }

    @ApiOperation("获取会议")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") String ID) {
        return success(baseMeetingService.selectBaseMeetingById(ID));
    }
}
